package com.taikang.hmp.hbusiness.diabetes.measure.medicine.action.view;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.taikang.hmp.frame.common.TKException;
import com.taikang.hmp.frame.common.datastructre.Dto;
import com.taikang.hmp.frame.common.datastructre.support.BaseDto;
import com.taikang.hmp.frame.common.datastructre.support.ResponseDto;
import com.taikang.hmp.frame.common.web.action.BaseAction;
import com.taikang.hmp.hbusiness.diabetes.measure.medicine.bean.Medicine;
import com.taikang.hmp.hbusiness.diabetes.measure.medicine.service.IMedicineService;

/** 
 * 用药
 * author:wyf
 * time:2015年8月25日 上午11:02:42
 */
public class MedicineViewAction extends BaseAction{
	private static Logger logger = LoggerFactory.getLogger(MedicineViewAction.class);

	private IMedicineService medicineService;
	

	public IMedicineService getMedicineService() {
		return medicineService;
	}

	public void setMedicineService(IMedicineService medicineService) {
		this.medicineService = medicineService;
	}

	public String executeAction()  {
		// 显示用药柱状图
		if ("showMedicineChart".equals(requestDto.getMethod())) {
			return showMedicineChart();
			// 显示运动表
		}else if("showMedicineTable".equals(requestDto.getMethod())){
			return showMedicineTable();
		}  else {
			throw new TKException("no support method:"+requestDto.getMethod());
		}
	}

	/**
	 * 显示用药柱状图
	 * @return
	 */
	public String showMedicineChart()  {
		ResponseDto responseDto = new ResponseDto();	
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		int[] records = medicineService.getMedicineChartList(paramDto);
		
		Dto dto = new BaseDto();
		dto.put("records", records);
		responseDto.pushResultDto(dto);
		super.setDataMap(responseDto);

		return SUCCESS;
	}	
	/**
	 * 显示用药记录表格
	 * 
	 * @return
	 */
	public String showMedicineTable()  {
		ResponseDto responseDto = new ResponseDto();	
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		List<Medicine> records = medicineService.getMedicineTableList(paramDto);
		Dto dto = new BaseDto();
		dto.put("records", records);
		responseDto.pushResultDto(dto);
		super.setDataMap(responseDto);
		
		return SUCCESS;
	}

}
